import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { MaterialVO, MaterialForm, MaterialQuery } from '@/api/base/material/types';

/**
 * 查询物料分页列表
 * @param query
 * @returns {*}
 */
export const pageMaterial = (query?: MaterialQuery): AxiosPromise<MaterialVO[]> => {
  return request({
    url: '/base/material/page',
    method: 'get',
    params: query
  });
};
/**
 * 查询物料列表
 * @param query
 * @returns {*}
 */
export const listMaterial = (query?: MaterialQuery): AxiosPromise<MaterialVO[]> => {
  return request({
    url: '/base/material/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询物料详细
 * @param materialId
 */
export const getMaterial = (materialId: string | number): AxiosPromise<MaterialVO> => {
  return request({
    url: '/base/material/' + materialId,
    method: 'get'
  });
};

/**
 * 新增物料
 * @param data
 */
export const addMaterial = (data: MaterialForm) => {
  return request({
    url: '/base/material',
    method: 'post',
    data: data
  });
};

/**
 * 修改物料
 * @param data
 */
export const updateMaterial = (data: MaterialForm) => {
  return request({
    url: '/base/material',
    method: 'put',
    data: data
  });
};

/**
 * 删除物料
 * @param materialId
 */
export const delMaterial = (materialId: string | number | Array<string | number>) => {
  return request({
    url: '/base/material/' + materialId,
    method: 'delete'
  });
};
